package com.cwd.arm.infrastructure.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cwd.arm.infrastructure.dao.RoleDao;
import com.cwd.arm.infrastructure.dao.base.DaoImpl;
import com.cwd.arm.infrastructure.mapper.RoleMapper;
import com.cwd.arm.infrastructure.po.RolePo;
import com.cwd.arm.infrastructure.query.RoleDaoQuery;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* Description:角色
* Created on 2021年11月15日
* @author  yan
*/
@Service
public class RoleDaoImpl extends DaoImpl<RoleMapper, RolePo> implements RoleDao {


    @Override
    public Page<RolePo> selectPage(RoleDaoQuery daoQuery) {
        Page<RolePo> poPage=new Page<>(daoQuery.getCurrentPage(),daoQuery.getPageSize());
        QueryWrapper<RolePo> queryWrapper = new QueryWrapper<>();
        baseMapper.selectPage(poPage,queryWrapper);
        setUserInfo(poPage.getRecords());
        return poPage;
    }

    @Override
    public List<RolePo> selectList(RoleDaoQuery daoQuery) {
        QueryWrapper<RolePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ObjectUtils.isNotEmpty(daoQuery.getUserId()),"user_id",daoQuery.getUserId());
        return list(queryWrapper);
    }
}
